home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / p4 / p4-1_2c.lha / p4-1.2c / misc / mutual.c < prev    next >
C/C++ Source or Header  |  1993-05-25  |  1KB  |  62 lines

  1. #include "p4.h"
  2.  
  3. extern void slave();
  4.  
  5. int main(argc,argv)
  6.      int argc;
  7.      char **argv;
  8. {
  9.   p4_initenv(&argc,argv);
  10.   p4_create_procgroup();
  11.  
  12.   slave();
  13.  
  14.   p4_wait_for_end();
  15. }
  16.  
  17. void slave()
  18. {
  19.     int i,j;
  20.     char *buffer;
  21.     int msg_len;
  22.     int len;
  23.     int type;
  24.     int me = p4_get_my_id();
  25.     int nproc = p4_num_total_ids();
  26.     
  27.     len = 32800;  /* fails with 32800 */
  28.     
  29.     if ( (buffer = p4_shmalloc((unsigned) len)) == (char *) NULL)
  30.     p4_error("Ring: failed to allocate buffer",len);
  31.   
  32.     type = 5;
  33.  
  34.     for (j = 0; j < 2; j++)
  35.     {
  36.     for(i=0; i<nproc; i++)
  37.         if (i!=me)
  38.         {
  39.         (void) p4_send(type,i, buffer, len);
  40.         (void) p4_send(type,i, buffer, len);
  41.     
  42.         }
  43.     for(i=0; i<nproc; i++)
  44.         if (i!=me)
  45.         {
  46.         msg_len = len;
  47.         (void) p4_recv(&type, &i, &buffer, &msg_len);
  48.         (void) p4_recv(&type, &i, &buffer, &msg_len);
  49.         }
  50.  
  51.     if (me == 0)
  52.         (void) printf("Messages whith %d bytes lenght sent and received\n",
  53.               len);
  54.     }
  55.     
  56.  
  57.     if (me == 0)
  58.     (void) p4_shfree(buffer);
  59.  
  60. }
  61.  
  62.